<template>
  <div class="container1 flex" style="background-color: #fff;" v-if="this.form.schoolName == '赵县中医院'">
    <div class="left">
      <p class="left_title">赵县中医院OA管理系统</p>
      <p class="left_content">全新一站式智能办公平台，全面提升医院办公管理新高度！</p>
      <img src="../assets/images/MedicalProductLoginBj.png">
    </div>
    <div class="right1">
      <p class="right_title"><span class="span1">欢迎登录</span><span class="span2">做管理 更专业</span></p>
      <div class="loginBox1" style="background-color: #fff;">
        <div class="loginTitle">
          <p>账号密码登录</p>
          <div></div>
        </div>
        <input class="text" type="text" placeholder="请输入账号" v-model="form.name">
        <input class="password" type="password" placeholder="请输入密码" v-model="form.password">
        <p class="noPassword"> </p>
        <button class="btn" @click="login">登录</button>
      </div>
    </div>
  </div>



  <div class="container" v-else>
    <div class="col-1">
      <div class="img_box">
        <div>
          <div class="h1">{{ schoolName }}<span>智慧医院</span></div>
          <div class="h3">{{ systemName }}</div>
        </div>
        <img class="login_img" src="../assets/phone-login-tu.png" alt="">
      </div>
    </div>
    <!-- 用户登录组件 -->
    <loginForm class="loginForm_box" ref="loginForm" />
  </div>
</template>

<script>
import loginForm from "@/components/login.vue";
import { getCurrentInstance } from "vue";
import { httpService } from "@/utils/httpService";
import { ElMessage, ElForm, ElLoading, } from "element-plus";

export default {
  name: "LoginView",
  components: { loginForm, ElMessage },
  setup() {
    const instance = getCurrentInstance()
    // console.log(instance);
    let schoolName = instance.appContext.config.globalProperties.$schoolName
    let systemName = instance.appContext.config.globalProperties.$systemName
    let appId = instance.appContext.config.globalProperties.$appId
    let redirect_uri = instance.appContext.config.globalProperties.$redirect_uri

    let showQrCode = instance.appContext.config.globalProperties.$showQrCode
    let skipSso = instance.appContext.config.globalProperties.$skipSso
    console.log({ appId: appId, redirect_uri: redirect_uri, schoolName: schoolName, systemName: systemName, showQrCode: showQrCode, skipSso: skipSso });
    return { appId: appId, redirect_uri: redirect_uri, schoolName: schoolName, systemName: systemName, showQrCode: showQrCode, skipSso: skipSso }
  },
  data() {
    return {
      form: {
        name: "",
        password: "",
        schoolName: "",
      }
    };
  },

  mounted() {
    const instance = getCurrentInstance()
    this.form.schoolName = instance.appContext.config.globalProperties.$schoolName


    this.$refs.loginForm.showQrCode = this.showQrCode;
    this.$refs.loginForm.redirect_uri = this.redirect_uri;
    this.$refs.loginForm.appId = this.appId;
    this.$refs.loginForm.isShow = this.showQrCode;
    this.$refs.loginForm.skipSso = this.skipSso;
    this.$refs.loginForm.getState();
    this.$refs.loginForm.init();
    this.$refs.loginForm.open();
    this.$refs.loginForm.createQrcode();
    this.$refs.loginForm.loginWx();
  },
  methods: {

    login() {
      if (!this.form.name) {
        ElMessage.error("请输入账号");
      } else if (!this.form.password) {
        ElMessage.error("请输入密码");
      } else {
        let params = new FormData();
        params.append("name", this.form.name);
        params.append("password", this.form.password);
        httpService("/javaApi/login", params, "post").then((data) => {
          if (data.code == 200) {
            sessionStorage.removeItem("token");
            sessionStorage.removeItem("user");
            sessionStorage.setItem("token", data.object.token);
            sessionStorage.setItem("user", JSON.stringify(data.object.data));
            //判断用户角色，如果是普通用户则跳转到普通用户首页
            this.$router.replace("index");
            ElMessage.success("登录成功");

          } else {
            ElMessage.error(data.message);
          }
        });
      }
    },
  },
};
</script>

<style scoped>
.h1 {
  font-size: 36px;
  text-align: center;
  font-weight: bold;
  color: #0552C0;
  /* padding-top: 150px; */
}

.h1 span {
  margin-left: 25px;
}

.h3 {
  font-size: 20px;
  /* color: #444444; */
  color: #0552C0;
  padding: 10px;
  text-align: center;
  margin-top: 10px;
}

#app,
body,
.container {
  min-height: 100%;
}

@media only screen and (max-width: 1024px) {
  body {
    margin: 0;
    /* height: 100%; */
    background: url(../assets/phone-login-bg.png) no-repeat;
    background-size: 100% 100%;
    /* background: url(../assets/login-background-mobile.png) no-repeat;
    background-size: cover; */
  }

  .col-1 {
    display: inline-block;
    *display: inline;
    *zoom: 1;
    width: 100%;
    /* height: 50%; */
    /* margin-top: 100px; */
  }

  .col-1 img {
    width: 90%;
    height: 90%;
    margin: 5% !important;
    /* padding-top: 10px; */
  }

  .container {
    background: url(../assets/phone-login-bg.png) no-repeat;
    background-size: 100% 100%;
    /* padding-bottom: 10px; */
  }

  .h1 {
    font-size: 26px;
    padding-top: 100px;
  }

  .h3 {
    font-size: 16px;
  }

}

@media only screen and (min-width: 1024px) {
  body {
    margin: 0;
    background: url(../assets/login_bg.png) no-repeat;
    background-image: url(../assets/login_bg.png);
    background-size: 100% 100%;
    /* background: url(../assets/login-background.png) no-repeat;
    background-size: cover; */
  }

  .col-1 {
    display: inline-block;
    *display: inline;
    *zoom: 1;
    width: 100%;
    /* margin-top: 100px; */
    /* margin-left: 15%; */
  }


  .container {
    display: flex;
    background: url(../assets/login_bg.png) no-repeat;
    background-size: 100% 100%;
    /* padding-top: 100px; */
    /* background: url(../assets/bg.png) repeat; */
  }

  .h1 {
    padding-top: 150px;
  }

  .login_img {
    height: 70%;
  }
}

/* .login_img {
  height: 70%;
} */

.img_box {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin-top: -70px;
  /* margin-left: 15%; */
}

.img_box>div {
  margin-bottom: -50px;
}








* {
  padding: 0;
  margin: 0;
}

.flex {
  display: flex;
  align-items: center;
}

.container1 {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
}

.left {
  width: 49vw;
  height: 100vh;
  background-color: #EEF7FB;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.left_title {
  color: #000;
  font-size: 30px;
  font-weight: bold;
  margin-top: -64px;
}

.left_content {
  color: #999999;
  font-size: 16px;
  margin-top: 37px;
}

.left img {
  width: 75%;
  margin-top: 26px;
}

.right1 {
  width: 51vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-left: 172px;
}

.right_title {
  margin-left: 36px;
  margin-top: -40px;
}

.right_title .span1 {
  font-size: 25px;
  color: #000;
  font-weight: bold;
}

.right_title .span2 {
  font-size: 18px;
  color: #999999;
  margin-left: 15px;
}

.loginBox1 {
  width: 460px;
  height: 453px;
  padding: 41px 36px 65px;
  border: 1px solid #DDDDDD;
  border-radius: 10px;
  box-sizing: border-box;
  margin-top: 29px;
}

.loginTitle {
  color: #000;
  font-size: 18px;
  font-weight: bold;

}

.loginTitle div {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background-color: #6F72FF;
  width: 107px;
  margin-top: 7px;
}

input {
  width: calc(100% - 18px);
  height: 58px;
  border: none;
  outline: none;
  background-color: #EFEFEF;
  border-radius: 10px;
  margin-top: 35px;
  font-size: 14px;
  color: #000;
  padding-left: 18px;
}

input::placeholder {
  color: #999999;
}

.noPassword {
  color: #6F72FF;
  margin: 10px 0 0 18px;
  font-size: 14px;
}

.btn {
  width: 100%;
  height: 58px;
  background-color: #6F72FF;
  color: #fff;
  font-size: 20px;
  border: none;
  border-radius: 29px;
  margin-top: 49px;
  cursor: pointer;
}
</style>
